﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

using TRPOP.CRM.Component.Business;
using TRPOP.CRM.Component.Model;
using TRPOP.Common;

namespace TRPOP.CRM.Component.Common
{
    /// <summary>
    /// 页面绑定帮助类
    /// </summary>
    public class PageBindHelper
    {
        /// <summary>
        /// 绑定所有的 客户类型
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindCompanyCategoryInfo(DropDownList oDropDownList)
        {
            List<CompanyCategoryInfo> oCompanyCategoryInfolist = BaseManage.GetAllCompanyCategoryInfo();

            foreach (CompanyCategoryInfo oInfo in oCompanyCategoryInfolist)
            {
                oInfo.nvcCompanyCategoryName = oInfo.nvcCompanyCategoryName.HtmlDecode();
            }

            oDropDownList.DataSource = oCompanyCategoryInfolist;

            oDropDownList.DataTextField = "nvcCompanyCategoryName";
            oDropDownList.DataValueField = "iCompanyCategoryID";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定所有客户等级
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindCompanyGradeInfo(DropDownList oDropDownList)
        {
            List<CompanyGradeInfo> oCompanyGradeInfolist = BaseManage.GetAllCompanyGradeInfo();

            foreach (CompanyGradeInfo oInfo in oCompanyGradeInfolist)
            {
                oInfo.nvcCompanyGradeName = oInfo.nvcCompanyGradeName.HtmlDecode();
            }

            oDropDownList.DataSource = oCompanyGradeInfolist;

            oDropDownList.DataTextField = "nvcCompanyGradeName";
            oDropDownList.DataValueField = "iCompanyGradeID";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定所有客户来源
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindCompanySourceInfo(DropDownList oDropDownList)
        {
            List<CompanySourceInfo> oCompanySourceInfolist = BaseManage.GetAllCompanySourceInfo();

            foreach (CompanySourceInfo oInfo in oCompanySourceInfolist)
            {
                oInfo.nvcCompanySourceName = oInfo.nvcCompanySourceName.HtmlDecode();
            }

            oDropDownList.DataSource = oCompanySourceInfolist;

            oDropDownList.DataTextField = "nvcCompanySourceName";
            oDropDownList.DataValueField = "iCompanySourceID";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定员工状态
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindEmployeeStatusInfo(DropDownList oDropDownList)
        {
            List<EmployeeStatuInfo> oEmployeeStatusInfolist = BaseManage.GetAllEmployeeStatuInfo();

            foreach (EmployeeStatuInfo oInfo in oEmployeeStatusInfolist)
            {
                oInfo.nvcStatusName = oInfo.nvcStatusName.HtmlDecode();
            }

            oDropDownList.DataSource = oEmployeeStatusInfolist;

            oDropDownList.DataTextField = "nvcStatusName";
            oDropDownList.DataValueField = "iEmployeeStatusID";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定所有职位信息
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindJobTitleInfo(DropDownList oDropDownList)
        {
            List<JobTitleInfo> oJobTitleInfoList = BaseManage.GetAllJobTitleInfo();

            foreach (JobTitleInfo oInfo in oJobTitleInfoList)
            {
                oInfo.nvcJobTitleName = oInfo.nvcJobTitleName.HtmlDecode();
            }

            oDropDownList.DataSource = oJobTitleInfoList;

            oDropDownList.DataTextField = "nvcJobTitleName";
            oDropDownList.DataValueField = "iJobTitleID";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定所有跟踪类型
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindFollowUpCategoryInfo(DropDownList oDropDownList)
        {
            List<FollowUpCategoryInfo> oFollowUpCategoryInfoList = BaseManage.GetAllFollowUpCategoryInfo();

            foreach (FollowUpCategoryInfo oInfo in oFollowUpCategoryInfoList)
            {
                oInfo.nvcFollowUpCategoryName = oInfo.nvcFollowUpCategoryName.HtmlDecode();
            }

            oDropDownList.DataSource = oFollowUpCategoryInfoList;

            oDropDownList.DataTextField = "nvcFollowUpCategoryName";
            oDropDownList.DataValueField = "iFollowUpCategoryID";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定所有提醒类型
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindRemindCategoryInfo(DropDownList oDropDownList)
        {
            List<RemindCategoryInfo> oRemindCategoryInfoList = BaseManage.GetAllRemindCategoryInfo();

            foreach (RemindCategoryInfo oRemindCategoryInfo in oRemindCategoryInfoList)
            {
                oRemindCategoryInfo.nvcRemindCategoryName = oRemindCategoryInfo.nvcRemindCategoryName.HtmlDecode();
            }

            oDropDownList.DataSource = oRemindCategoryInfoList;

            oDropDownList.DataTextField = "nvcRemindCategoryName";
            oDropDownList.DataValueField = "iRemindCategoryID";

            oDropDownList.DataBind();
        }
 
        /// <summary>
        /// 绑定所有的部门信息
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindDepartmentInfo(DropDownList oDropDownList, int intExceptID)
        {
            List<DepartmentLevel> oDepartmentInfoList = DepartmentManage.GetAllDepartmentTree(0, string.Empty);

            if (intExceptID > 0)
            {
                oDepartmentInfoList.RemoveAll(oDepartmentLevel => oDepartmentLevel.iDepartmentID == intExceptID);
            }

            foreach (DepartmentLevel oDepartmentLevel in oDepartmentInfoList)
            {
                oDepartmentLevel.nvcDepartmentName = oDepartmentLevel.nvcDepartmentName.HtmlDecode();
            }

            oDropDownList.DataSource = oDepartmentInfoList;

            oDropDownList.DataTextField = "nvcDepartmentName";
            oDropDownList.DataValueField = "iDepartmentID";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定 所有的客户状态
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindCompanyStatus(DropDownList oDropDownList)
        {
            oDropDownList.DataSource = SystemConst.AllCompanyStatus();

            oDropDownList.DataTextField = "Value";
            oDropDownList.DataValueField = "Key";

            oDropDownList.DataBind();
        }

        /// <summary>
        /// 绑定所有的 系统角色
        /// </summary>
        /// <param name="oDropDownList"></param>
        public static void BindSystemRole(DropDownList oDropDownList)
        {
            oDropDownList.DataSource = PermissionManage.GetAllSystemRoleInfo();

            oDropDownList.DataTextField = "nvcRoleName";
            oDropDownList.DataValueField = "iSystemRoleID";

            oDropDownList.DataBind();
        }
    }
}
